<head>

<style type="text/css" title="currentStyle" media="screen">
	@import "vtes_exp.css";
</style>

<script type="text/javascript">

	function popup(mylink, windowname) {
		if (! window.focus)return true;
		var href;
		if (typeof(mylink) == 'string')
		   href=mylink;
		else
		   href=mylink.href;
		window.open(href, windowname, 'width=240,height=320,scrollbars=no');
			return false;
		}

	function go(page) {
        document.pageform.page.value = page;
        if (document.pageform.name_search.value == "(enter search text)")
            document.pageform.name_search.value = "";
		document.forms[0].submit();
		}

    function go_sub(page, next_card) {
        document.pageform.next_card.value = next_card;
        go(page);
        // document.pageform.page.value = page;
		// document.forms[0].submit();
        }

    function card_popup(card_name, card_type) {
        if (card_type == "L")
            open("card.php?card=" + card_name, "card", "toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,height=400,width=600,top=150,left=300");
        else
            open("crypt.php?card=" + card_name, "card", "toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,height=400,width=600,top=150,left=300");
        }

    function image_popup(card_name) {
        open("image.php?card=" + card_name, "card", "toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,height=325,width=275,top=150,left=300");
        return false;
        }
        
        
</script>

<script type="text/javascript" src="util-functions.js"></script>
<script type="text/javascript" src="clear-default-text.js"></script>

</head>
<body>

<?php
// session_start();

if (isset($_POST['submitted']) && $_POST['submitted'] == 'submitted')
    $reset = false;
else {
    $_POST["page"] = -1;
    $_POST["library"] = "true";
    $_POST["name_search"] = "";
    $_POST["next_card"] = "";
    $_POST["thumbs"] = "back";
    $_POST["type"] = "all";
    $_POST["clan"] = "all";
    $_POST["discipline"] = "all";
    $_POST["jyh"] = "all";
    $_POST["vts"] = "all";
    $_POST["ds"] = "all";
    $_POST["ah"] = "all";
    $_POST["sab"] = "all";
    $_POST["sbw"] = "all";
    $_POST["fn"] = "all";
    $_POST["bld"] = "all";
    $_POST["cam"] = "all";
    $_POST["an"] = "all";
    $_POST["bh"] = "all";
    $_POST["geh"] = "all";
    $_POST["ten"] = "all";
    $_POST["kmw"] = "all";
    $_POST["lob"] = "all";
    $_POST["nor"] = "all";
    $_POST["3rd"] = "all";
    $_POST["soc"] = "all";
    $_POST["pro"] = "all";
    $_POST["dem"] = "all";
	$reset = true;
    }
if ($_POST["name_search"] == "(enter search text)")
    $_POST["name_search"] = "";
    
$page_size = 25;
$page_span_start = $_POST["page"];
$page_span_end = $_POST["page"];
$next_card = str_replace("{","'",$_POST["next_card"]);
$prev_card = "";
?>


<?php

//  Now we start processing the data.

$expansions = array(2 => "jyh", "vts", "ds", "ah", "sab", "sbw", "fn", "bld", "cam", "an", "bh", "geh", "ten", "kmw", "lob", "nor", "3rd", "soc", "pro", "dem");

//  Read all our data files
$c = 0;
$file = fopen("db_types.csv", "r");
fgetcsv($file, 1000, ",");   // ditch the first line
while  (($types[$c] = fgetcsv($file, 1000, ",")) !== FALSE) {
    $c++;
    }
fclose($file);

$c = 0;
$file = fopen("db_images.csv","r");
fgetcsv($file, 1000, ",");   // ditch the first line
while  (($images[$c] = fgetcsv($file, 1000, ",")) !== FALSE) {
    $c++;
    }
fclose($file);

$c = 0;
$file = fopen("db_rarities.csv","r");
fgetcsv($file, 1000, ",");   // ditch the first line
while  (($rarity[$c] = fgetcsv($file, 1000, ",")) !== FALSE) {
    $c++;
    }
fclose($file);

// Set up a few counters for the following loop
$c = 0;
$c_start = 0;
$c_end = 0;

$icon_link_text = "";

//  Iterate over every card until our list of matches is full 
foreach ($images as $idx => $card) {
    
    // This is the loop that develops the list of cards to display.
    //
    // It's complicated.

    // Eiminate all invalid card *types* from consideration.
    switch ($types[$idx][1]) {
        case "Master":
            if (($_POST["type"] !== "master" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Combat":
            if (($_POST["type"] !== "combat" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Combat / Reaction":
        case "Reaction / Combat":
            if (($_POST["type"] !== "combat" && $_POST["type"] !== "reaction" &&  $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Action":
            if (($_POST["type"] !== "action" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Action / Combat":
            if (($_POST["type"] !== "action" && $_POST["type"] !== "combat" &&  $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Action / Reaction":
            if (($_POST["type"] !== "action" && $_POST["type"] !== "reaction" &&  $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Action Modifier":
            if (($_POST["type"] !== "actionmod" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Action Modifier / Combat":
        case "Combat / Action Modifier":
            if (($_POST["type"] !== "actionmod" && $_POST["type"] !== "combat" &&  $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Action Modifier / Reaction":
        case "Reaction / Action Modifier":
            if (($_POST["type"] !== "reaction" && $_POST["type"] !== "actionmod" &&  $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Political Action":
            if (($_POST["type"] !== "political" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Reaction":
            if (($_POST["type"] !== "reaction" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Equipment":
            if (($_POST["type"] !== "equipment" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Ally":
            if (($_POST["type"] !== "ally" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Retainer":
            if (($_POST["type"] !== "retainer" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Event":
            if (($_POST["type"] !== "event" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Power":
            if (($_POST["type"] !== "power" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Conviction":
            if (($_POST["type"] !== "conviction" && $_POST["type"] !== "all") || $_POST["library"] == "false")
                continue 2;
            break;
        case "Vampire":
            if (($_POST["type"] !== "vampire" && $_POST["type"] !== "all") || $_POST["library"] == "true")
                continue 2;
            break;
        case "Imbued":
            if (($_POST["type"] !== "imbued" && $_POST["type"] !== "all") || $_POST["library"] == "true")
                continue 2;
           break;
        default:
            // echo "<tr><td>Error - bad card type - [.$idx.][".$types[$idx][0]."][".$types[$idx][1]."]</td></tr>\n";
            continue 2;
        }

    // Now do the same thing by clan. Sort out all of the cards that don't match our current clan setting.
    if ($_POST["clan"] !== "all") {
        if ($_POST["clan"] == "none") {
            if ($types[$idx][2] !== " ")
                continue;
            }
        else if ($_POST["clan"] !== strtolower($types[$idx][2])) {
            if (ereg("/",$types[$idx][2])) {
                $search_str = "(^".$_POST["clan"]." /)|(/ ".$_POST["clan"]."$)";   // (^malkavian /)|(/ malkavian$)
                // echo "[$search_str]";
                if (ereg($search_str,strtolower($types[$idx][2])) == false)
                    continue;
                }
            else
                // echo "[".$_POST["clan"]."]:[".strtolower($types[$idx][2])."]\n";
                continue;
            }
        }
    
    if ($_POST["discipline"] !== "all") {
        if ($_POST["discipline"] == "none") {
            if ($types[$idx][3] !== " ")
                continue;
            }
        else if ($_POST["discipline"] == "only") {
            if ($types[$idx][3] == " ")
                continue;
            }
        else {
            $discipline_data = preg_split("/ ?[\/&] ?/",$types[$idx][3]);
            // print_r($discipline_data);
            $want = false;
            foreach ($discipline_data as $dis) {
                switch ($_POST["discipline"]) {
                    case "thn":
                        if ($dis == "Thanatosis") {
                            $want = true;
                            break 2;
                            }
                        break;
                    case "tha":
                        if ($dis == "Thaumaturgy") {
                            $want = true;
                            break 2;
                            }
                        break;
                    case "vis":
                        if ($dis == "Visceratika") {
                            $want = true;
                            break 2;
                            }
                        break;
                    case "vsn":
                        if ($dis == "Vision") {
                            $want = true;
                            break 2;
                            }
                        break;
                    default:
                        if (strtolower(substr($dis,0,3)) == $_POST["discipline"]) {
                            $want = true;
                            break 2;
                            }
                        break;
                    }
                }
            if (!$want)
                continue;
            }
        }
    
    // Now do the same thing by rarity.  There is 1 rarity setting per expansion, so we loop across all the expansions,
    // and look for filter criteria to reject cards by.
    
    // echo "$card[0]: ";
    foreach ($rarity[$idx] as $key => $val) {
        if ($key <= 1)  // skip the first field
            continue;
       
        $exp = $expansions[$key];
        // echo "[$key]=[$exp]:";
        // if ($key == 2) {

            if ($_POST[$exp] == "only") {
                if ($val == " ")
                    continue 2;
                else
                    continue ;
                }

            // If we want all of this expansion, drop out of loop and collect it.
            if ($_POST[$exp] == "all") 
                continue;

            // If we want none of this expansion, continue 2 will reset the main card loop.
            //
            // Note that the "null" value for these fields is " ", and that HTML eats whitespace,
            // making this difficult to detect.  Fun.
            if ($_POST[$exp] == "none") {
                if ($val == " ") 
                    continue;
                continue 2;
                }

            // Now we know that we have a specific rarity selected.  Test the first letter to see
            // if it's an invalid match, and if so, reset the loop.
            
            // echo "$key, $val, ";
            else if ($exp == "ten") {
                // Special case: Tenth Anniversary Set has slightly different rules.  It can be set to "A", "B", or "AB".
                // Thus, we use a strstr() search instead of just examining the first letter.
                if ($val !== "A/B" && $_POST[$exp] !== $val{0})
                    continue 2;
                }
            else if ($_POST[$exp] !== substr($val,0,1))
                continue 2;
            
            // We have found no reason to bail on the card, so keep it.
            else
               continue;
        //    }
        }

    // Now look for any specific name searches they have entered, and eliminate everything that doesn't match
    // that search.
    if ($_POST["name_search"] !== "") {
        if (strstr(strtolower($card[0]),strtolower($_POST["name_search"])) == false)
            continue;
        }


    // If we've made it this far, this card is a candidate for display.  In general, what we're doing is 
    // collecting cards until we fill up our display window ($page_size).

    // increment our "# found" counter
    $c++;
    $card_list_full[$c] = $card[0];
    
    // Eliminate any cards that start with a letter lower than our current letter page value.
    //
    // We do this first because it's startlingly cheap.
    if (ord($card[0]{0}) < ord("A") + $page_span_start)
        if ($card[0]{0} !== "." || $page_span_start > -1)
            continue;

    // Furthermore, if we have a "next card" from a previous page, we can just skip everything until we find that card.
    if ($next_card !== "") {
        if ($card[0] == $next_card)
            $next_card = "";
        else
            continue;
        }
        
    // This first case catches the case of the very first card after our page has filled up.  We use this section to set up our page data
    // for the nav bar.
    if (count($card_list) == $page_size) {
        $next_card = $card[0];
        if ($card[0]{0} == ".")
            $page_span_end = -1;
        else
            $page_span_end = ord($card[0]{0}) - ord("A");
        
        $c_end = $c;
        
        // And, since we've hit the end of the list, we can just quit cycling.
        // break;
        }

    // Otherwise, just collect the card.
    elseif (count($card_list) < $page_size) {
        if ($c_start == 0)
            $c_start = $c;
        $card_list[$idx] = $card;
        // $c++;
        }
    }

// Clean up if we had fewer than a full page of cards in the result
if (count($card_list) < $page_size) {
    $next_card = "";
    $page_span_end = 25;
    $c_end = $c;
    }
?>


<!-- Now it's time to actually output our HTML page -->

<!-- whole damn page is a form -->
<form action="index.php" method="post" name="pageform">
    <input type="hidden" name="submitted" value="submitted" />

<!-- TITLE BAR -->
<div id="left_side">
    <div id="search_stats_pane">
        <input type="hidden" name="page" value="<?php echo $_POST["page"]; ?>" />
        <input type="hidden" name="next_card" value="" />
        <p><b>Search Type</b><br><br>
        <label for="library_button" id="library_select" ><input type="radio" name="library" id="library_button" value="true"<?php if ($_POST["library"] == "true") echo ' checked="checked"'; ?> onchange="document.forms[0].submit();" /><img src="icon/_card_back_vts_library.jpg" alt="Library" border="0"></label><br><br>
        <label for="crypt_button" id="library_select" ><input type="radio" name="library" id="crypt_button" value="false"<?php if ($_POST["library"] == "false") echo ' checked="checked"'; ?> onchange="document.forms[0].submit();" /><img src="icon/_card_back_vts_crypt.jpg" alt="Crypt" border="0"></label></p>
        
        <p><b>Site Stats</b><br>
        Scanned: 5143<br>
        Missing: 413</p>

        <p><b>Search Stats</b><br>
        <?php echo "<b>$c</b> matches<br>Viewing <b>$c_start</b> - <b>$c_end</b>" ?></p>
        
        <p><b>Thumbnails</b><br>
        <label id="thumbs_backs"><input type="radio" name="thumbs" id="thumbs_backs" value="back"<?php if ($_POST["thumbs"] == "back") echo ' checked="checked"'; ?> onchange="document.forms[0].submit();" /><img <?php if ($_POST["library"] == "true") echo "src=\"th/_back_lib_vts_th.jpg\""; else echo "src=\"th/_back_cry_vts_th.jpg\""; ?> alt="Backs"></label><br>
        <label id="thumbs_fronts"><input type="radio" name="thumbs" id="thumbs_fronts" value="front"<?php if ($_POST["thumbs"] == "front") echo ' checked="checked"'; ?> onchange="document.forms[0].submit();" /><img <?php if ($_POST["library"] == "true") echo "src=\"th/44_magnum_jyh_th.jpg\""; else echo "src=\"th/aabbt_kindred_fn_th.jpg\""; ?> alt="Fronts"></label></p>
     </div>
</div>

<!-- MAIN TABLE -->
<div id="card_list">

<table class="card_table">

<!-- table title bar -->
<tr>
    <th class="nav_table" colspan="4">
    
    <table border="0" class="nav_table">
        <tr><td class="nav_table" colspan="27"><h1>The VTES Explorer</h1></td></tr>
        <tr>
            <td class="nav_table" colspan="27">
            </td>
        </tr>
        <tr><td class="nav_table" style="height: 10px;">&nbsp;</td></tr>
        <tr>
<?php
    // Do the "before this page" links
    for ($i = -1; $i < $_POST["page"]; $i++) {
        echo "<td class=\"nav_table\">";
        echo "<a href=\"index.php\" onclick=\"go($i); return false;\">";
        if ($i == -1)
            echo "#";
        else
            echo chr(ord("A") + $i);
        echo "</a>";
        echo "</td>\n";
        }

    //  Do the "this page" link
    echo "<td class=\"nav_table\">";
    if ($i == -1)
        echo "#";
    else
        echo chr(ord("A") + $_POST["page"]);
    echo "</td>\n";
    // if ($page_curr !== $_POST["page"])
    //     echo "- ".chr(ord("A") + $page_curr)." ";

    //  Do the "after this page" links
    for ($i = $_POST["page"] + 1; $i < 26; $i++) {
        echo "<td class=\"nav_table\">";
        echo "<a href=\"index.php\" onclick=\"go($i); return false;\">";
        if ($i == -1)
            echo "#";
        else
            echo chr(ord("A") + $i);
        echo "</a>";
        echo "</td>\n";
        }
?>
        </tr>
        <tr>
<?php
    // Do the "before this page" links
    for ($i = -1; $i < $page_span_start - 1; $i++) {
        echo "<td class=\"nav_table\"></td>\n";
        }

    if ($page_span_start > -1) {
        if ($c_start <= $page_size)
            $prev_card = $card_list_full[1];
        else
            $prev_card = $card_list_full[$c_start - $page_size];
        if ($prev_card{0} == ".")
            $prev_page = -1;
        else
            $prev_page = ord($prev_card{0}) - ord("A");
        echo "<td class=\"nav_table\">";
        echo "<a href=\"index.php\" onclick='go_sub($prev_page,\"".str_replace("'","{",$prev_card)."\"); return false;'>";
        echo "<";
        echo "</a></td>\n";
        $i++;
        }

    for ( ; $i <= $page_span_end; $i++) {
        echo "<td class=\"nav_table\">-</td>\n";
        }
    
    if ($i < 25) {
        echo "<td class=\"nav_table\">";
        echo "<a href=\"index.php\" onclick='go_sub($i-1,\"".str_replace("'","{",$next_card)."\"); return false;'>";
        echo ">";
        echo "</a></td>\n";
        $i++;
        }

    //  Do the "after this page" links
    for ( ; $i < 26; $i++) {
        echo "<td class=\"nav_table\"></td>\n";
        }
?>
        </tr>
    </table>

    </th>
    <!-- <th class="title"></th>
    <th class="title"></th> -->
    <th class="title"><img src="icon/icon_jyh_text.jpg" alt="Jyhad" width=16px></th>
    <th class="title"><img src="icon/icon_vts_text.jpg" alt="V:TES" width=16px></th>
    <th class="title"><img src="icon/icon_ds_text.jpg" alt="DS" width=16px></th>
    <th class="title"><img src="icon/icon_ah_text.jpg" alt="AH" width=16px></th>
    <th class="title"><img src="icon/icon_sab_text.jpg" alt="Sabbat" width=16px></th>
    <th class="title"><img src="icon/icon_sbw_text.jpg" alt="S. War" width=16px></th>
    <th class="title"><img src="icon/icon_fn_text.jpg" alt="FN" width=16px></th>
    <th class="title"><img src="icon/icon_bld_text.jpg" alt="Bld" width=16px></th>
    <th class="title"><img src="icon/icon_cam_text.jpg" alt="Cam" width=16px></th>
    <th class="title"><img src="icon/icon_an_text.jpg" alt="Anarchs" width=16px></th>
    <th class="title"><img src="icon/icon_bh_text.jpg" alt="BH" width=16px></th>
    <th class="title"><img src="icon/icon_geh_text.jpg" alt="Gehenna" width=16px></th>
    <th class="title"><img src="icon/icon_ten_text.jpg" alt="Tenth" width=16px></th>
    <th class="title"><img src="icon/icon_kmw_text.jpg" alt="KMW" width=16px></th>
    <th class="title"><img src="icon/icon_lob_text.jpg" alt="LoB" width=16px></th>
    <th class="title"><img src="icon/icon_nor_text.jpg" alt="NoR" width=16px></th>
    <th class="title"><img src="icon/icon_3rd_text.jpg" alt="Third" width=16px></th>
    <th class="title"><img src="icon/icon_soc_text.jpg" alt="SoC" width=16px></th>
    <th class="title"><img src="icon/icon_pro_text.jpg" alt="Promo" width=16px></th>
    <th class="title"><img src="icon/icon_dem_text.jpg" alt="Demo" width=16px></th>
</tr>
<tr>
    <th class="title">Name</th>
    <th class="title">Type</th>
    <th class="title">Clan/Creed</th>
    <th class="title">Discipline</th>
    <th class="title"><img src="icon/icon_blank_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_vts_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_ds_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_ah_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_sab_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_sbw_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_fn_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_bld_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_cam_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_an_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_bh_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_geh_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_ten_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_kmw_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_lob_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_nor_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_3rd_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_blank_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_blank_th.jpg" width=16px></th>
    <th class="title"><img src="icon/icon_dem_th.jpg" width=16px></th>
</tr>

<!-- search controls -->
<tr><td class="title"><input class="title_name_search" name="name_search" type="text" <?php if ($_POST["name_search"] == "") echo "value=\"(enter search text)\""; else echo "value=\"".$_POST["name_search"]."\""; ?> /></td>
    <td class="title"><select class="title_type" name="type" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["type"] == "all") echo ' selected="selected"'; ?> >all</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="master" <?php if ($_POST["type"] == "master") echo ' selected="selected"'; ?> >Master</option>
        <option value="combat" <?php if ($_POST["type"] == "combat") echo ' selected="selected"'; ?> >Combat</option>
        <option value="action" <?php if ($_POST["type"] == "action") echo ' selected="selected"'; ?> >Action</option>
        <option value="actionmod" <?php if ($_POST["type"] == "actionmod") echo ' selected="selected"'; ?> >Action Modifier</option>
        <option value="reaction" <?php if ($_POST["type"] == "reaction") echo ' selected="selected"'; ?> >Reaction</option>
        <option value="political" <?php if ($_POST["type"] == "political") echo ' selected="selected"'; ?> >Political Action</option>
        <option value="equipment" <?php if ($_POST["type"] == "equipment") echo ' selected="selected"'; ?> >Equipment</option>
        <option value="ally" <?php if ($_POST["type"] == "ally") echo ' selected="selected"'; ?> >Ally</option>
        <option value="retainer" <?php if ($_POST["type"] == "retainer") echo ' selected="selected"'; ?> >Retainer</option>
        <option value="event" <?php if ($_POST["type"] == "event") echo ' selected="selected"'; ?> >Event</option>
        <option value="power" <?php if ($_POST["type"] == "power") echo ' selected="selected"'; ?> >Power</option>
        <option value="conviction" <?php if ($_POST["type"] == "conviction") echo ' selected="selected"'; ?> >Conviction</option>
<?php } else { ?>
        <option value="vampire" <?php if ($_POST["type"] == "vampire") echo ' selected="selected"'; ?> >Vampire</option>
        <option value="imbued" <?php if ($_POST["type"] == "imbued") echo ' selected="selected"'; ?> >Imbued</option>
<?php } ?>
    </select></td>
    <td class="title"><select class="title_clan" name="clan" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["clan"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="none" <?php if ($_POST["clan"] == "none") echo ' selected="selected"'; ?> >none</option>
        <optgroup label="Camarilla">
            <option value="brujah" <?php if ($_POST["clan"] == "brujah") echo ' selected="selected"'; ?> >Brujah</option>
            <option value="caitiff" <?php if ($_POST["clan"] == "caitiff") echo ' selected="selected"'; ?> >Caitiff</option>
            <option value="malkavian" <?php if ($_POST["clan"] == "malkavian") echo ' selected="selected"'; ?> >Malkavian</option>
            <option value="nosferatu" <?php if ($_POST["clan"] == "nosferatu") echo ' selected="selected"'; ?> >Nosferatu</option>
            <option value="toreador" <?php if ($_POST["clan"] == "toreador") echo ' selected="selected"'; ?> >Toreador</option>
            <option value="tremere" <?php if ($_POST["clan"] == "tremere") echo ' selected="selected"'; ?> >Tremere</option>
            <option value="ventrue" <?php if ($_POST["clan"] == "ventrue") echo ' selected="selected"'; ?> >Ventrue</option>
        </optgroup>
        <optgroup label="Sabbat">
            <option value="brujah antitribu" <?php if ($_POST["clan"] == "brujah antitribu") echo ' selected="selected"'; ?> >Brujah <i>antitribu</i></option>
            <option value="gangrel antitribu" <?php if ($_POST["clan"] == "gangrel antitribu") echo ' selected="selected"'; ?> >Gangrel <i>antitribu</i></option>
            <option value="lasombra" <?php if ($_POST["clan"] == "lasombra") echo ' selected="selected"'; ?> >Lasombra</option>
            <option value="malkavian antitribu" <?php if ($_POST["clan"] == "malkavian antitribu") echo ' selected="selected"'; ?> >Malkavian <i>antitribu</i></option>
            <option value="nosferatu antitribu" <?php if ($_POST["clan"] == "nosferatu antitribu") echo ' selected="selected"'; ?> >Nosferatu <i>antitribu</i></option>
            <option value="pander" <?php if ($_POST["clan"] == "pander") echo ' selected="selected"'; ?> >Pander</option>
            <option value="toreador antitribu" <?php if ($_POST["clan"] == "toreador antitribu") echo ' selected="selected"'; ?> >Toreador <i>antitribu</i></option>
            <option value="tremere antitribu" <?php if ($_POST["clan"] == "tremere antitribu") echo ' selected="selected"'; ?> >Tremere <i>antitribu</i></option>
            <option value="tzimisce" <?php if ($_POST["clan"] == "tzimisce") echo ' selected="selected"'; ?> >Tzimisce</option>
            <option value="ventrue antitribu" <?php if ($_POST["clan"] == "ventrue antitribu") echo ' selected="selected"'; ?> >Ventrue <i>antitribu</i></option>
        </optgroup>
        <optgroup label="Laibon">
            <option value="akunanse" <?php if ($_POST["clan"] == "akunanse") echo ' selected="selected"'; ?> >Akunanse</option>
            <option value="guruhi" <?php if ($_POST["clan"] == "guruhi") echo ' selected="selected"'; ?> >Guruhi</option>
            <option value="ishtarri" <?php if ($_POST["clan"] == "ishtarri") echo ' selected="selected"'; ?> >Ishtarri</option>
            <option value="osebo" <?php if ($_POST["clan"] == "osebo") echo ' selected="selected"'; ?> >Osebo</option>
        </optgroup>
        <optgroup label="Independent">
            <option value="abomination" <?php if ($_POST["clan"] == "abomination") echo ' selected="selected"'; ?> >Abomination</option>
            <option value="assamite" <?php if ($_POST["clan"] == "assamite") echo ' selected="selected"'; ?> >Assamite</option>
            <option value="follower of set" <?php if ($_POST["clan"] == "follower of set") echo ' selected="selected"'; ?> >Follower of Set</option>
            <option value="gangrel" <?php if ($_POST["clan"] == "gangrel") echo ' selected="selected"'; ?> >Gangrel</option>
            <option value="giovanni" <?php if ($_POST["clan"] == "giovanni") echo ' selected="selected"'; ?> >Giovanni</option>
            <option value="ravnos" <?php if ($_POST["clan"] == "ravnos") echo ' selected="selected"'; ?> >Ravnos</option>
        </optgroup>
        <optgroup label="Bloodlines - Sabbat">
            <option value="ahrimane" <?php if ($_POST["clan"] == "ahrimane") echo ' selected="selected"'; ?> >Ahrimane</option>
            <option value="blood brother" <?php if ($_POST["clan"] == "blood brother") echo ' selected="selected"'; ?> >Blood Brother</option>
            <option value="harbinger of skulls" <?php if ($_POST["clan"] == "harbinger of skulls") echo ' selected="selected"'; ?> >Harbinger of Skulls</option>
            <option value="kiasyd" <?php if ($_POST["clan"] == "kiasyd") echo ' selected="selected"'; ?> >Kiasyd</option>
            <option value="salubri antitribu" <?php if ($_POST["clan"] == "salubri antitribu") echo ' selected="selected"'; ?> >Salubri <i>antitribu</i></option>
        </optgroup>
        <optgroup label="Bloodlines - Independent">
            <option value="baali" <?php if ($_POST["clan"] == "baali") echo ' selected="selected"'; ?> >Baali</option>
            <option value="daughter of cacophony" <?php if ($_POST["clan"] == "daughter of cacophony") echo ' selected="selected"'; ?> >Daughter of Cacophony</option>
            <option value="gargoyle" <?php if ($_POST["clan"] == "gargoyle") echo ' selected="selected"'; ?> >Gargoyle</option>
            <option value="nagaraja" <?php if ($_POST["clan"] == "nagaraja") echo ' selected="selected"'; ?> >Nagaraja</option>
            <option value="salubri" <?php if ($_POST["clan"] == "salubri") echo ' selected="selected"'; ?> >Salubri</option>
            <option value="samedi" <?php if ($_POST["clan"] == "samedi") echo ' selected="selected"'; ?> >Samedi</option>
            <option value="true brujah" <?php if ($_POST["clan"] == "true brujah") echo ' selected="selected"'; ?> >True Brujah</option>
        </optgroup>
        <optgroup label="Imbued">
            <option value="avenger" <?php if ($_POST["clan"] == "avenger") echo ' selected="selected"'; ?> >Avenger</option>
            <option value="defender" <?php if ($_POST["clan"] == "defender") echo ' selected="selected"'; ?> >Defender</option>
            <option value="innocent" <?php if ($_POST["clan"] == "innocent") echo ' selected="selected"'; ?> >Innocent</option>
            <option value="judge" <?php if ($_POST["clan"] == "judge") echo ' selected="selected"'; ?> >Judge</option>
            <option value="martyr" <?php if ($_POST["clan"] == "martyr") echo ' selected="selected"'; ?> >Martyr</option>
            <option value="redeemer" <?php if ($_POST["clan"] == "redeemer") echo ' selected="selected"'; ?> >Redeemer</option>
            <option value="visionary" <?php if ($_POST["clan"] == "visionary") echo ' selected="selected"'; ?> >Visionary</option>
        </optgroup>
    </select></td>
    <td class="title"><select class="title_discipline" name="discipline" onchange="go(-1);">
        <option value="all" <?php if ($_POST["discipline"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["discipline"] == "only") echo ' selected="selected"'; ?> >only</option>
        <option value="none" <?php if ($_POST["discipline"] == "none") echo ' selected="selected"'; ?> >none</option>
        <optgroup label="Disciplines">
            <option value="ani" <?php if ($_POST["discipline"] == "ani") echo ' selected="selected"'; ?> >Animalism</option>
            <option value="aus" <?php if ($_POST["discipline"] == "aus") echo ' selected="selected"'; ?> >Auspex</option>
            <option value="cel" <?php if ($_POST["discipline"] == "cel") echo ' selected="selected"'; ?> >Celerity</option>
            <option value="chi" <?php if ($_POST["discipline"] == "chi") echo ' selected="selected"'; ?> >Chimerstry</option>
            <option value="dai" <?php if ($_POST["discipline"] == "dai") echo ' selected="selected"'; ?> >Daimionon</option>
            <option value="dem" <?php if ($_POST["discipline"] == "dem") echo ' selected="selected"'; ?> >Dementation</option>
            <option value="dom" <?php if ($_POST["discipline"] == "dom") echo ' selected="selected"'; ?> >Dominate</option>
            <option value="for" <?php if ($_POST["discipline"] == "for") echo ' selected="selected"'; ?> >Fortitude</option>
            <option value="mel" <?php if ($_POST["discipline"] == "mel") echo ' selected="selected"'; ?> >Melpominee</option>
            <option value="myt" <?php if ($_POST["discipline"] == "myt") echo ' selected="selected"'; ?> >Mytherceria</option>
            <option value="nec" <?php if ($_POST["discipline"] == "nec") echo ' selected="selected"'; ?> >Necromancy</option>
            <option value="obe" <?php if ($_POST["discipline"] == "obe") echo ' selected="selected"'; ?> >Obeah</option>
            <option value="obf" <?php if ($_POST["discipline"] == "obf") echo ' selected="selected"'; ?> >Obfuscate</option>
            <option value="obt" <?php if ($_POST["discipline"] == "obt") echo ' selected="selected"'; ?> >Obtenebration</option>
            <option value="pot" <?php if ($_POST["discipline"] == "pot") echo ' selected="selected"'; ?> >Potence</option>
            <option value="pre" <?php if ($_POST["discipline"] == "pre") echo ' selected="selected"'; ?> >Presence</option>
            <option value="pro" <?php if ($_POST["discipline"] == "pro") echo ' selected="selected"'; ?> >Protean</option>
            <option value="qui" <?php if ($_POST["discipline"] == "qui") echo ' selected="selected"'; ?> >Quietus</option>
            <option value="san" <?php if ($_POST["discipline"] == "san") echo ' selected="selected"'; ?> >Sanguinus</option>
            <option value="ser" <?php if ($_POST["discipline"] == "ser") echo ' selected="selected"'; ?> >Serpentus</option>
            <option value="spi" <?php if ($_POST["discipline"] == "spi") echo ' selected="selected"'; ?> >Spiritus</option>
            <option value="tem" <?php if ($_POST["discipline"] == "tem") echo ' selected="selected"'; ?> >Temporis</option>
            <option value="tha" <?php if ($_POST["discipline"] == "tha") echo ' selected="selected"'; ?> >Thaumaturgy</option>
            <option value="thn" <?php if ($_POST["discipline"] == "thn") echo ' selected="selected"'; ?> >Thanatosis</option>
            <option value="val" <?php if ($_POST["discipline"] == "val") echo ' selected="selected"'; ?> >Valeren</option>
            <option value="vic" <?php if ($_POST["discipline"] == "vic") echo ' selected="selected"'; ?> >Vicissitude</option>
            <option value="vis" <?php if ($_POST["discipline"] == "vis") echo ' selected="selected"'; ?> >Visceratika</option>
        </optgroup>
        <optgroup label="Virtues">
            <option value="def" <?php if ($_POST["discipline"] == "def") echo ' selected="selected"'; ?> >Defense</option>
            <option value="inn" <?php if ($_POST["discipline"] == "inn") echo ' selected="selected"'; ?> >Innocence</option>
            <option value="jud" <?php if ($_POST["discipline"] == "jud") echo ' selected="selected"'; ?> >Judgement</option>
            <option value="mar" <?php if ($_POST["discipline"] == "mar") echo ' selected="selected"'; ?> >Martyrdom</option>
            <option value="red" <?php if ($_POST["discipline"] == "red") echo ' selected="selected"'; ?> >Redemption</option>
            <option value="ven" <?php if ($_POST["discipline"] == "ven") echo ' selected="selected"'; ?> >Vengeance</option>
            <option value="vsn" <?php if ($_POST["discipline"] == "vsn") echo ' selected="selected"'; ?> >Vision</option>
        </optgroup>
    </select></td>
    <!-- <td class="title"><select class="title" name="jyh" onchange="document.forms[0].submit();"> -->
    <td class="title"><select class="title" name="jyh" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["jyh"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["jyh"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["jyh"] == "R") echo ' selected="selected"'; ?> >R</option>
        <option value="U" <?php if ($_POST["jyh"] == "U") echo ' selected="selected"'; ?> >U</option>
        <option value="C" <?php if ($_POST["jyh"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } else { ?>
        <option value="V" <?php if ($_POST["jyh"] == "V") echo ' selected="selected"'; ?> >V</option>
<?php } ?>
        <option value="none" <?php if ($_POST["jyh"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="vts" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["vts"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["vts"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["vts"] == "R") echo ' selected="selected"'; ?> >R</option>
        <option value="U" <?php if ($_POST["vts"] == "U") echo ' selected="selected"'; ?> >U</option>
        <option value="C" <?php if ($_POST["vts"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } else { ?>
        <option value="V" <?php if ($_POST["vts"] == "V") echo ' selected="selected"'; ?> >V</option>
<?php } ?>
        <option value="none" <?php if ($_POST["vts"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="ds" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["ds"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["ds"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="U" <?php if ($_POST["ds"] == "U") echo ' selected="selected"'; ?> >U</option>
        <option value="C" <?php if ($_POST["ds"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } else { ?>
        <option value="V" <?php if ($_POST["ds"] == "V") echo ' selected="selected"'; ?> >V</option>
<?php } ?>
        <option value="none" <?php if ($_POST["ds"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="ah" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["ah"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["ah"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["ah"] == "R") echo ' selected="selected"'; ?> >R</option>
        <option value="U" <?php if ($_POST["ah"] == "U") echo ' selected="selected"'; ?> >U</option>
        <option value="C" <?php if ($_POST["ah"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } else { ?>
        <option value="V" <?php if ($_POST["ah"] == "V") echo ' selected="selected"'; ?> >V</option>
<?php } ?>
        <option value="none" <?php if ($_POST["ah"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="sab" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["sab"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["sab"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["sab"] == "R") echo ' selected="selected"'; ?> >R</option>
        <option value="U" <?php if ($_POST["sab"] == "U") echo ' selected="selected"'; ?> >U</option>
        <option value="C" <?php if ($_POST["sab"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } else { ?>
        <option value="V" <?php if ($_POST["sab"] == "V") echo ' selected="selected"'; ?> >V</option>
<?php } ?>
        <option value="none" <?php if ($_POST["sab"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="sbw" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["sbw"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["sbw"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["sbw"] == "R") echo ' selected="selected"'; ?> >R</option>
<?php } ?>
        <option value="U" <?php if ($_POST["sbw"] == "U") echo ' selected="selected"'; ?> >U</option>
        <option value="C" <?php if ($_POST["sbw"] == "C") echo ' selected="selected"'; ?> >C</option>
        <option value="P" <?php if ($_POST["sbw"] == "P") echo ' selected="selected"'; ?> >P</option>
        <option value="none" <?php if ($_POST["sbw"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="fn" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["fn"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["fn"] == "only") echo ' selected="selected"'; ?> >only</option>
        <option value="R" <?php if ($_POST["fn"] == "R") echo ' selected="selected"'; ?> >R</option>
        <option value="U" <?php if ($_POST["fn"] == "U") echo ' selected="selected"'; ?> >U</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="C" <?php if ($_POST["fn"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } ?>
        <option value="P" <?php if ($_POST["fn"] == "P") echo ' selected="selected"'; ?> >P</option>
        <option value="none" <?php if ($_POST["fn"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="bld" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["bld"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["bld"] == "only") echo ' selected="selected"'; ?> >only</option>
        <option value="R" <?php if ($_POST["bld"] == "R") echo ' selected="selected"'; ?> >R</option>
        <option value="U" <?php if ($_POST["bld"] == "U") echo ' selected="selected"'; ?> >U</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="C" <?php if ($_POST["bld"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } ?>
        <option value="none" <?php if ($_POST["bld"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="cam" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["cam"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["cam"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["cam"] == "R") echo ' selected="selected"'; ?> >R</option>
        <option value="U" <?php if ($_POST["cam"] == "U") echo ' selected="selected"'; ?> >U</option>
        <option value="C" <?php if ($_POST["cam"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } ?>
        <option value="P" <?php if ($_POST["cam"] == "P") echo ' selected="selected"'; ?> >P</option>
<?php if ($_POST["library"] == "false") { ?>
        <option value="V" <?php if ($_POST["cam"] == "V") echo ' selected="selected"'; ?> >V</option>
<?php } ?>
        <option value="none" <?php if ($_POST["cam"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="an" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["an"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["an"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["an"] == "R") echo ' selected="selected"'; ?> >R</option>
<?php } ?>
        <option value="U" <?php if ($_POST["an"] == "U") echo ' selected="selected"'; ?> >U</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="C" <?php if ($_POST["an"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } ?>
        <option value="P" <?php if ($_POST["an"] == "P") echo ' selected="selected"'; ?> >P</option>
        <option value="none" <?php if ($_POST["an"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="bh" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["bh"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["bh"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["bh"] == "R") echo ' selected="selected"'; ?> >R</option>
<?php } ?>
        <option value="U" <?php if ($_POST["bh"] == "U") echo ' selected="selected"'; ?> >U</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="C" <?php if ($_POST["bh"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } ?>
        <option value="P" <?php if ($_POST["bh"] == "P") echo ' selected="selected"'; ?> >P</option>
        <option value="none" <?php if ($_POST["bh"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="geh" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["geh"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["geh"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["geh"] == "R") echo ' selected="selected"'; ?> >R</option>
<?php } else { ?>
        <option value="U" <?php if ($_POST["geh"] == "U") echo ' selected="selected"'; ?> >U</option>
<?php }
      if ($_POST["library"] == "true") { ?>
        <option value="C" <?php if ($_POST["geh"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } ?>
        <option value="none" <?php if ($_POST["geh"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="ten" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["ten"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["ten"] == "only") echo ' selected="selected"'; ?> >only</option>
        <option value="A" <?php if ($_POST["ten"] == "A") echo ' selected="selected"'; ?> >A</option>
        <option value="B" <?php if ($_POST["ten"] == "B") echo ' selected="selected"'; ?> >B</option>
        <option value="none" <?php if ($_POST["ten"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="kmw" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["kmw"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["kmw"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["kmw"] == "R") echo ' selected="selected"'; ?> >R</option>
<?php } else { ?>
        <option value="U" <?php if ($_POST["kmw"] == "U") echo ' selected="selected"'; ?> >U</option>
<?php }
      if ($_POST["library"] == "true") { ?>
        <option value="C" <?php if ($_POST["kmw"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } ?>
        <option value="P" <?php if ($_POST["kmw"] == "P") echo ' selected="selected"'; ?> >P</option>
        <option value="none" <?php if ($_POST["kmw"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="lob" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["lob"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["lob"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["lob"] == "R") echo ' selected="selected"'; ?> >R</option>
<?php } ?>
        <option value="U" <?php if ($_POST["lob"] == "U") echo ' selected="selected"'; ?> >U</option>
        <option value="C" <?php if ($_POST["lob"] == "C") echo ' selected="selected"'; ?> >C</option>
        <option value="P" <?php if ($_POST["lob"] == "P") echo ' selected="selected"'; ?> >P</option>
        <option value="none" <?php if ($_POST["lob"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="nor" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["nor"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["nor"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["nor"] == "R") echo ' selected="selected"'; ?> >R</option>
<?php } else { ?>
        <option value="U" <?php if ($_POST["nor"] == "U") echo ' selected="selected"'; ?> >U</option>
<?php }
      if ($_POST["library"] == "true") { ?>
        <option value="C" <?php if ($_POST["nor"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } ?>
        <option value="none" <?php if ($_POST["nor"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="3rd" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["3rd"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["3rd"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["3rd"] == "R") echo ' selected="selected"'; ?> >R</option>
        <option value="U" <?php if ($_POST["3rd"] == "U") echo ' selected="selected"'; ?> >U</option>
        <option value="C" <?php if ($_POST["3rd"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } ?>
        <option value="P" <?php if ($_POST["3rd"] == "P") echo ' selected="selected"'; ?> >P</option>
<?php if ($_POST["library"] == "false") { ?>
        <option value="V" <?php if ($_POST["3rd"] == "V") echo ' selected="selected"'; ?> >V</option>
<?php } ?>
        <option value="none" <?php if ($_POST["3rd"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="soc" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["soc"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["soc"] == "only") echo ' selected="selected"'; ?> >only</option>
<?php if ($_POST["library"] == "true") { ?>
        <option value="R" <?php if ($_POST["soc"] == "R") echo ' selected="selected"'; ?> >R</option>
        <option value="C" <?php if ($_POST["soc"] == "C") echo ' selected="selected"'; ?> >C</option>
<?php } else { ?>
        <option value="V" <?php if ($_POST["soc"] == "V") echo ' selected="selected"'; ?> >V</option>
<?php } ?>
        <option value="none" <?php if ($_POST["soc"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="pro" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["pro"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["pro"] == "only") echo ' selected="selected"'; ?> >only</option>
        <option value="none" <?php if ($_POST["pro"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
    <td class="title"><select class="title" name="dem" onchange="go(-1);">
        <option value="all" <?php if ($reset || $_POST["dem"] == "all") echo ' selected="selected"'; ?> >all</option>
        <option value="only" <?php if ($_POST["dem"] == "only") echo ' selected="selected"'; ?> >only</option>
        <option value="none" <?php if ($_POST["dem"] == "none") echo ' selected="selected"'; ?> >none</option>
    </select></td>
</tr>

<?php

// Output the table we found.

if (count($card_list) == 0) {
    echo "<tr><td class=\"card_name\" colspan=\"23\"><h2><p>(No cards meet the current search criteria. Check your crypt/library status and/or your rarities.</p><p>Remember that, in some expansions, uncommon cards are exclusively crypt cards.)</p></h2></td></tr>";
    }
else {
    foreach ($card_list as $idx => $card) {
        echo "<tr><td class=\"card_name\"><h2>";
        if (strlen($card[0]) >= 30)
            echo "<span class=\"smaller\">";
        echo "<a";
        switch (substr($rarity[$idx][1],0,1)) {
            case "R":
                echo " class=\"rare\"";
                break;
            case "U":
            case "V":
                echo " class=\"uncommon\"";
                break;
            case "C":
                echo " class=\"common\"";
                break;
            case "A":
            case "B":
            case "P":
                echo " class=\"prebuilt\"";
                break;
            case "1":
            case "2":   // Promos have the date in the rarity field.
                echo " class=\"promo\">";
                break;
            default:
                echo " class=\"promo\"";
                
                echo '>';
                break;
            } 
        // echo " href=\"".$card[0]."\" onclick='open(\"card.php?card=".str_replace("'","{",$card[0])."\", \"card\", \"toolbar=0,menubar=0,location=0,status=0,directories=0,scrollbars=1,height=400,width=600,top=150,left=300\"); return false;'>";
        echo " href=\"".$card[0]."\" onclick='card_popup(\"".str_replace("'","{",$card[0])."\",";
        if ($types[$idx][1] == "Vampire" || $types[$idx][1] == "Imbued")
            echo "\"C\"";
        else
            echo "\"L\"";
        echo "); return false;'>";
        echo $card[0];
        echo "</a>";
        if (strlen($card[0]) >= 30)
            echo "</span>";
        echo "</h2></td>";
    
        // echo "<td class=\"card_type\"><h3>";
        echo "<td class=\"card_type\">";
        if (strlen($types[$idx][1]) >= 16)
            echo "<span class=\"much_smaller\">";
        // echo $types[$idx][1];
        $img_tag_open = "<img src=\"icon/icon_type_";
        $img_tag_mid = "_16.jpg\" border=\"0\" height=16px width=16px title=\"";
        $img_tag_close = "\" >";
        echo $img_tag_open;
        switch ($types[$idx][1]) {
            case "Master":
                echo "master".$img_tag_mid."Master".$img_tag_close;
                break;
            case "Combat":
                echo "combat".$img_tag_mid."Combat".$img_tag_close;
                break;
            case "Combat / Reaction":
                echo "combat".$img_tag_mid."Combat".$img_tag_close.$img_tag_open."reaction".$img_tag_mid."Reaction".$img_tag_close;
                break;
            case "Reaction / Combat":
                echo "reaction".$img_tag_mid."Reaction".$img_tag_close.$img_tag_open."combat".$img_tag_mid."Combat".$img_tag_close;
                break;
            case "Action":
                echo "action".$img_tag_mid."Action".$img_tag_close;
                break;
            case "Action / Combat":
                echo "action".$img_tag_mid."Action".$img_tag_close.$img_tag_open."combat".$img_tag_mid."Combat".$img_tag_close;
                break;
            case "Action / Reaction":
                echo "action".$img_tag_mid."Action".$img_tag_close.$img_tag_open."reaction".$img_tag_mid."Reaction".$img_tag_close;
                break;
            case "Action Modifier":
                echo "actionmod".$img_tag_mid."Action Modifier".$img_tag_close;
                break;
            case "Action Modifier / Combat":
                echo "actionmod".$img_tag_mid."Action Modifier".$img_tag_close.$img_tag_open."combat".$img_tag_mid."Combat".$img_tag_close;
                break;
            case "Combat / Action Modifier":
                echo "combat".$img_tag_mid."Combat".$img_tag_close.$img_tag_open."actionmod".$img_tag_mid."Action Modifier".$img_tag_close;
                break;
            case "Action Modifier / Reaction":
                echo "actionmod".$img_tag_mid."Action Modifier".$img_tag_close.$img_tag_open."reaction".$img_tag_mid."Reaction".$img_tag_close;
                break;
            case "Reaction / Action Modifier":
                echo "reaction".$img_tag_mid."Reaction".$img_tag_close.$img_tag_open."actionmod".$img_tag_mid."Action Modifier".$img_tag_close;
                break;
            case "Political Action":
                echo "political".$img_tag_mid."Political Action".$img_tag_close;
                break;
            case "Reaction":
                echo "reaction".$img_tag_mid."Reaction".$img_tag_close;
                break;
            case "Equipment":
                echo "equipment".$img_tag_mid."Equipment".$img_tag_close;
                break;
            case "Ally":
                echo "ally".$img_tag_mid."Ally".$img_tag_close;
                break;
            case "Retainer":
                echo "retainer".$img_tag_mid."Retainer".$img_tag_close;
                break;
            case "Event":
                echo "event".$img_tag_mid."Event".$img_tag_close;
                break;
            case "Power":
                echo "power".$img_tag_mid."Power".$img_tag_close;
                break;
            case "Conviction":
                echo "conviction".$img_tag_mid."Conviction".$img_tag_close;
                break;
            case "Vampire":
                echo "master".$img_tag_mid."Vampire".$img_tag_close;
                break;
            case "Imbued":
                echo "master".$img_tag_mid."Imbued".$img_tag_close;
                break;
            default:
                echo "badcardtype\">";
            }

        if (strlen($types[$idx][1]) >= 20)
            echo "</span>";
        echo "</h3></td>";
        // echo "</td>";

        // echo "<td class=\"card_clan\"><h3>";
        echo "<td class=\"card_clan\">";
        if ($types[$idx][2] !== " ") {
            if ($types[$idx][1] == "Imbued")
                echo "<img src=\"icon/icon_creed_";
            else
                echo "<img src=\"icon/icon_clan_";
            if (ereg("/",$types[$idx][2])) {
                switch ($types[$idx][2]) {
                    case "Tremere / Tremere antitribu":
                        echo "tremere_24.jpg\" border=\"0\" height=24 width=24><img src=\"icon/icon_clan_tremere_antitribu";
                        break;
                    case "Malkavian / Malkavian antitribu":
                        echo "malkavian_24.jpg\" border=\"0\" height=24 width=24><img src=\"icon/icon_clan_malkavian_antitribu";
                        break;
                    default:
                        echo "ERROR";
                        break;
                    }
                }
            else
                {
                echo str_replace(" ","_",strtolower($types[$idx][2]));
                }
            echo "_24.jpg\" border=\"0\" height=24 width=24>";
            /*
            if (strlen($types[$idx][2]) >= 10)
                echo "<span class=\"much_smaller\">";
            echo $types[$idx][2];
            if (strlen($types[$idx][2]) >= 10)
                echo "</span>";
            */
            }
        // echo "</h3></td>";
        echo "</td>";

        // echo "<td class=\"card_discipline\"><h3>";
        echo "<td class=\"card_discipline\">";
        if ($types[$idx][3] !== " ") {
            $img_tag_open = "<img src=\"icon/icon_dis_";
            $img_tag_close = "_16.jpg\" border=\"0\" height=16px width=16px>";
        
            $discipline_data = preg_split("/ ?[\/&] ?/",$types[$idx][3]);
            // print_r($discipline_data);
            foreach ($discipline_data as $dis) {
                echo $img_tag_open;
                if ($dis == "Thanatosis")
                    echo "thn";
                else if ($dis == "Vision")
                    echo "vsn";
                else
                    echo strtolower(substr($dis,0,3));
                echo $img_tag_close;
                }
            }
        // echo "</h3></td>";
        echo "</td>";

        foreach ($images[$idx] as $key => $val) {
            if ($key <= 1)  // skip the first field
                continue;
            echo '<td ';
            if ($val == '' or $val == ' ')
                echo 'class="card_blank">';
            else {
                switch (substr($rarity[$idx][$key],0,1)) {
                    case "R":
                        echo 'class="card_rare">';
                        break;
                    case "U":
                    case "V":
                        echo 'class="card_unc">';
                        break;
                    case "C":
                        echo 'class="card_common">';
                        break;
                    case "A":
                    case "B":
                    case "P":
                        echo 'class="card_pre">';
                        break;
                    case "1":
                    case "2":   // Promos have the date in the rarity field.
                        echo 'class="card_promo">';
                        break;
                    default:
                        echo 'bad_data="'.$rarity[$idx][$key]{0}.'">';
                        break;
                    }
                if ($val == 'x')
                    echo $val;
                elseif ($val !== '' and $val !== ' ') {
                    echo "<a href=\"../ebay/$val\" onclick='image_popup(\"".str_replace("'","{",$card[0])."&exp=".$expansions[$key]."\"); return false;'>";
                    if ($_POST["thumbs"] == "front")
                        echo "<img src=\"th/".substr($val,0,-4)."_th.jpg\" border=\"0\" height=24px width=16px>";
                    else {
                        switch ($types[$idx][1]) {
                            case "Vampire":
                            case "Imbued":
                                if ($key == 2)
                                    echo "<img src=\"th/_back_cry_jyh_th.jpg\" border=\"0\" height=24px width=16px>";
                                else
                                    echo "<img src=\"th/_back_cry_vts_th.jpg\" border=\"0\" height=24px width=16px>";
                                break;
                            default:
                                if ($key == 2)
                                    echo "<img src=\"th/_back_lib_jyh_th.jpg\" border=\"0\" height=24px width=16px>";
                                else
                                    echo "<img src=\"th/_back_lib_vts_th.jpg\" border=\"0\" height=24px width=16px>";
                                break;
                            }
                        }
                    echo "</a>";
                    }
                }
            echo "</td>";
            }
        echo "</tr>\n";
        }
    }
?>

</table>


<?php

echo '<pre>';
echo "PID=[".getmypid()."]<br>";
foreach ($_POST as $key => $value) {
	echo '$_POST'."[$key]=[$value]\n";
	}
echo "\$page_span_start=[$page_span_start]\n";
echo "\$page_span_end=[$page_span_end]\n";
echo "\$next_card=[$next_card]\n";
echo "\$prev_card=[$prev_card]\n";
echo '</pre>';

?>

</div>

</form>

<form action="card.php" method="post" name="cardform" target="_blank">
    <input type="hidden" name="card" value="none">
</form>

</body>
</html>